package fifis.base.model;

import fifis.mvc.model.FModel;
import org.apache.log4j.Logger;

/**
 *
 * @author porfiriopartida
 */
public abstract class BModel extends FModel {

    protected final static Logger log4j = Logger.getLogger(BModel.class);
    static final long serialVersionUID = 1L;
    private int maxHp;
    private int hp;
    private int attack;
    private int defense;

    public BModel(String name, int maxHp, int attack, int defense) {
        super(name);
        setMaxHp(maxHp);
        setHp(maxHp);
        setAttack(attack);
        setDefense(defense);
    }

    public BModel(String name) {
        this(name, 0, 0, 0);
    }

    public int getDefense() {
        return defense;
    }

    public final void setDefense(int defense) {
        if (defense < 0) {
            defense = 0;
        }
        this.defense = defense;
    }

    public final int getMaxHp() {
        return maxHp;
    }

    public final void setMaxHp(int maxHp) {
        if (maxHp < 1) {
            maxHp = 1;
        }
        log4j.debug("MaxHP: " + maxHp);
        log4j.debug("HP: " + getHp());
        this.maxHp = maxHp;
        if (getHp() >= maxHp) {
            log4j.debug("New MaxHP is lower than current hp. Decreasing to maxHp = " + maxHp);
            setHp(maxHp);
        }
    }

    public final int getAttack() {
        return attack;
    }

    public final void setAttack(int attack) {
        if (attack < 0) {
            attack = 0;
        }
        this.attack = attack;
    }

    public final int getHp() {
        return hp;
    }

    public final void setHp(int hp) {
        if (hp > maxHp) {
            hp = maxHp;
        } else if (hp < 0) {
            hp = 0;
        }
        log4j.debug("Old current hp: " + this.hp);
        this.hp = hp;
        log4j.debug("New current hp: " + this.hp);
    }
}
